<template>
	<div class="cn">
		<div class="topimg">
			<img src="../../static/images/organize_team/ad-028.png">
		</div>
		<div class="cn_top">
			<!-- 顶部商家详情 -->
			<business-detail :detailinfo="header_info" v-if="header_info" :sharedata="posterdata"></business-detail>
			<div>
				<yd-tab>
					<yd-tab-panel label="点菜">
						<business-menu :menus="menus.menulist" ></business-menu>
					</yd-tab-panel>
					<!-- 评论列表start -->
					<yd-tab-panel label="评价">
						<div class="pl">
							<evaluatop :shlistev="fundby_bussines"></evaluatop>
							<evaluate :list="comments.comment_list"></evaluate>
						</div>
					</yd-tab-panel>
					<!-- 商家信息start -->
					<yd-tab-panel label="商家信息">
						<detail :shinfo="bussines"></detail>
					</yd-tab-panel>
				</yd-tab>
			</div>
		</div>
		<settlement :shid="business_id"></settlement>
	</div>
</template>
<script>
import businessDetail from '@/components/business_detail/business_header'
import businessMenu from '@/components/business_detail/menu'
import evaluate from '@/components/business_detail/evaluate'
import detail from '@/components/business_detail/detail';
import settlement from '@/components/business_detail/settlement'
import evaluatop from '@/components/business_detail/evaluatop'


export default {
	name: 'test',
	data () {
		return {
			business_id: 0,
			// 海报对象数据
			posterdata:{
				shname:'',
				shadress:'',
				shiphone:'',
				shurl:'',
				shlogo:''
			},
			// 商家顶部信息
			header_info: {
				// bussinesName: '袁家村关中印象体验店',
				// bussinesLabel: [{
				// 	icon: require('@/static/images/organize_team/rz.png'),
				// 	label: '高新店铺'
				// }, {
				// 	icon: require('@/static/images/organize_team/rs.png'),
				// 	label: '品牌专营'
				// }, {
				// 	icon: require('@/static/images/organize_team/tj.png'),
				// 	label: '放心吃'
				// }],
				// bussinesActivity: [{
				// 	icon: 'h',
				// 	title: '惠',
				// 	content: '新用户立减13元（不可与其他优惠同时享用），首次使用支付最高再减5元'
				// },
				// {
				// 	icon: 'm',
				// 	title: '买',
				// 	content: '满200减60，满200减60，满200减60，满200减60，满200减60，满200减60，'
				// }, {
				// 	icon: 'z',
				// 	title: '折',
				// 	content: '折扣商品7折起'
				// },
				// {
				// 	icon: 's',
				// 	title: '送',
				// 	content: '满200元送水果盘一份'
				// }
				// ],
			},
			page_size: 10,
			// 菜单列表
			menus: {
				page_index: 1,
				menulist: [
					// {
					// 	bussinesId:1,
					// 	dishesImage: require('@/static/images/organize_team/zs2.png'),
					// 	dishesName: '招牌！小厨娘酸菜鱼（大份）',
					// 	dishesDesc: '浓郁鸡汤的豆汤你懂得这只是测试用的产品介绍...',
					// 	monthAmount: 999,
					// 	praiseRate: 99,
					// 	presentPrice: 666,
					// 	dishesPrice: 999,
					// 	discount: 4,
					// 	num:0
					// },
					// {
					// 	id:2,
					// 	goods_img: require('@/static/images/organize_team/zs2.png'),
					// 	goods_name: '招牌！小厨娘酸菜鱼（大份）',
					// 	goods_synopsis: '浓郁鸡汤的豆汤你懂得这只是测试用的产品介绍...',
					// 	sales_volume: 999,
					// 	praise: 99,
					// 	price: 666,
					// 	original_price: 999,
					// 	discount: 4,
					// 	num:0
					// },
				]
			},
			//评价列表
			comments: {
				page_index: 1,
				comment_list: [
					// {
					//     headpic:require('@/static/images/organize_team/name.png'),
					//     userName:'匿名用户',
					//     createTime:'2019-11-23',
					//     bussinesEvaluate:4,
					//     headpic:'好吃到爆',
					//     evaluateImg:[
					//         require('@/static/images/organize_team/zs2.png'),
					//         require('@/static/images/organize_team/zs2.png'),
					//         require('@/static/images/organize_team/zs2.png'),
					//    ]

					// }
				]
			},
			bussines: {
				merchantAddress: '',
				bussinesTime: '',
				merchantPhone: '',
			},
			fundby_bussines: {
				bussinesEvaluate: 0,    //商家综合评价
				flavorEvaluate: 0,      //商家口味综合评价
				serviceEvaluate: 0,     //商家服务综合评价
				praise: ''               //综合好评

			}
		}
	},
	components: {
		businessDetail, //顶部商家详情
		businessMenu, //菜单
		evaluate, //评价
		detail, //商家详情
		settlement, //底部结算
		evaluatop //商家头部综合评价
	},
	mounted () {
		
		this.business_id =parseInt(this.$route.params.id) ||0
		this.$store.commit('BUSINESS_ID', this.business_id)
		this.get_business_detail();
		this.get_menus();
		this.get_comment_list_by_page();
		this.get_check_businesse_valuate();
		this.get_fundby_bussines();
		this.geturl();
	},
	methods: {
		/*
		* 获取菜单列表
		* 作者：gzt
		* 时间：2019-11-25 20:54:52
		*/
		get_menus () {
			let _this = this;
			this.$post(this.$api.organizeteam.get_dishes, {
				pageSize: this.page_size,
				pageNum: this.menus.page_index,
				request: {
					bussinesId: this.business_id
				}
			}).then(res => {
				if (res.success) {
					_this.menus.menulist = [..._this.menus.menulist, ...res.data.result];
					if (res.data.result.length < this.page_size) {
						/* 所有数据加载完毕 */
						_this.$refs.stores.$emit("ydui.infinitescroll.loadedDone");
						return;
					}
					/* 单次请求数据完毕 */
					_this.$refs.stores.$emit("ydui.infinitescroll.finishLoad");

					_this.menus.page_index++;
				} else {
					// 获取数据失败，跳转到公共错误页面
				}
			}).catch(res => {
				//异常，跳转到公共错误页面
			});
		},
		/*
		* 获取商户详情信息
		* 作者：gzt
		* 时间：2019-11-25 20:55:02
		*/
		get_business_detail () {
			let _this = this;
			this.$post(this.$api.organizeteam.get_bussines_title, {
				bussinesId: this.business_id
			}).then(res => {
				if (res.success) {
					_this.header_info = res.data;
					_this.posterdata.shname = _this.header_info.bussinesName;//海报数据商户名称
					_this.posterdata.shlogo = _this.header_info.bussinesLogo;//海报数据商户logo
				} else {
					// 获取数据失败，跳转到公共错误页面
				}
			}).catch(res => {
				//异常，跳转到公共错误页面
			});
		},
		/*
		* 分页获取评价列表
		* 作者：gzt
		* 时间：2019-11-25 20:55:39
		*/
		get_comment_list_by_page (page_index) {
			let _this = this;
			this.$post(this.$api.organizeteam.get_select, {
				pageSize: this.page_size,
				pageNum: this.comments.page_index,
				request: {
					bussinesId: this.business_id
				}
			}).then(res => {
				if (res.success) {

					_this.comments.comment_list = [..._this.comments.comment_list, ...res.data.result];
					for (var item of _this.comments.comment_list) {
						item.bussinesEvaluate = parseInt(item.bussinesEvaluate / 2)
					}

					if (res.data.result.length < this.page_size) {
						/* 所有数据加载完毕 */
						_this.$refs.stores.$emit("ydui.infinitescroll.loadedDone");
						return;
					}
					/* 单次请求数据完毕 */
					_this.$refs.stores.$emit("ydui.infinitescroll.finishLoad");

					_this.stores.page_index++;
				} else {
					// 获取数据失败，跳转到公共错误页面
				}
			}).catch(res => {
				//异常，跳转到公共错误页面
			});
		},
		// 查询指定商家头部综合评价
		get_check_businesse_valuate () {
			let _this = this;
			this.$post(this.$api.organizeteam.check_businesse_valuate, {
				bussinesId: this.business_id
			}).then(res => {
				if (res.success) {
					_this.fundby_bussines = res.data;
					_this.fundby_bussines.bussinesEvaluate = parseInt(parseFloat(_this.fundby_bussines.bussinesEvaluate) / 2)
					_this.fundby_bussines.flavorEvaluate = parseInt(parseFloat(_this.fundby_bussines.flavorEvaluate) / 2)
					_this.fundby_bussines.serviceEvaluate = parseInt(parseFloat(_this.fundby_bussines.serviceEvaluate) / 2)
				}
			}).catch(res => {
				//异常，跳转到公共错误页面
			});
		},
		// 查询指定商家信息
		get_fundby_bussines () {
			let _this = this;
			this.$post(this.$api.organizeteam.get_fundby_buss, {
				bussinesId: this.business_id
			}).then(res => {
				if (res.success) {
					_this.bussines = res.data;
					_this.posterdata.shadress = _this.bussines.merchantAddress;//海报数据商户地址
					_this.posterdata.shiphone = _this.bussines.merchantPhone;//海报数据商户电话
				}
			}).catch(res => {
				//异常，跳转到公共错误页面
			});
		},
		// 获取当前店铺的链接地址
        geturl (){
           this.posterdata.shurl = window.location.href;
		   
		}

	}

}
</script>
<style scoped>
.pl {
	padding: 0.3rem 0rem;
}
.topimg {
	padding: 0 0.3rem;
}

.topimg img {
	width: 100%;
}

.cn_top {
	padding: 0.3rem;

	top: 1.3rem;
}
</style>
